/*****************************************************************************
*  Copyright Statement:
*  --------------------
*  This software is protected by Copyright and the information contained
*  herein is confidential. The software may not be copied and the information
*  contained herein may not be used or disclosed except with the written
*  permission of MediaTek Inc. (C) 2005
*
*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
*
*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/
/*****************************************************************************
*
* Filename:
* ---------
*  CallLogLayout.c
*
* Project:
* --------
*  MAUI
*
* Description:
* ------------
*  
*
* Author:
* -------
*  Kefeng Lian (MTK80043)
*                      
*============================================================================
*             HISTORY
* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*------------------------------------------------------------------------------
* $Log$
 *
 * 09 08 2010 kefeng.lian
 * removed!
 * .
 *
 * 08 07 2010 kefeng.lian
 * removed!
 * .
 *
 * 08 03 2010 fachao.zhang
 * removed!
 * .
 *
 * 07 27 2010 kefeng.lian
 * removed!
 * .
 *
 * removed!
 * removed!
 * 
 *
 * removed!
 * removed!
 * 
 *
 * removed!
 * removed!
 * 
 *
 * removed!
 * removed!
 * 
 *
 * removed!
 * removed!
 * 
 *
 * removed!
 * removed!
 * 
 *
 * removed!
 * removed!
 * 
 *
 * removed!
 * removed!
 * 
 *
 * removed!
 * removed!
 * 
 *
 * removed!
 * removed!
 * 
 *
 * removed!
 * removed!
 * 
 *
 * removed!
 * removed!
 * 
 *
 * removed!
 * removed!
 * 
 *
 * removed!
 * removed!
 * 
*
* 
*
*------------------------------------------------------------------------------
* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*============================================================================
****************************************************************************/

#include "MMI_include.h"

/*----------------------------------------------------------------------------*/
/* Comments                                                                   */
/*----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------*/
/* Include                                                                    */
/*----------------------------------------------------------------------------*/
#include "wgui_touch_screen.h"  /* mmi_tap_type_enum */
#include "UcmGprot.h"
#include "CallLogProt.h"
#include "CallLogLayout.h"
#include "CallLogViewer.h"

/*----------------------------------------------------------------------------*/
/* Constant                                                                   */
/*----------------------------------------------------------------------------*/
#define  MMI_CLOG_LT_FLAG_SUP_MERGE                 (0x0001)
#define  MMI_CLOG_LT_FLAG_SUP_THREAD                (0x0002)
#define  MMI_CLOG_LT_FLAG_CUR_SEL_IDX_CHANGED       (0x0004)
/*----------------------------------------------------------------------------*/
/* Macro                                                                      */
/*----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------*/
/* typedef                                                                    */
/*----------------------------------------------------------------------------*/
typedef GetItemFuncPtr MMI_CLOG_LT_GET_ITEM_HDLR;
typedef GetHintFuncPtr MMI_CLOG_LT_GET_HINT_HDLR;

typedef FuncPtr MMI_CLOG_LT_TAB_HDLR;

#ifdef __MMI_FTE_SUPPORT__
typedef GUIIconbarItemCallback MMI_CLOG_LT_TB_HDLR;
typedef void (*MMI_CLOG_LT_TAP_HDLR) (mmi_tap_type_enum tap_type, S32 index);
#endif /* __MMI_FTE_SUPPORT__ */ 

/*----------------------------------------------------------------------------*/
/* Enum                                                                       */
/*----------------------------------------------------------------------------*/

typedef enum
{
    MMI_CLOG_LT_TB_ID_MAKE_CALL = 0x01,
    MMI_CLOG_LT_TB_ID_SEND_MSG = 0x02,
    MMI_CLOG_LT_TB_ID_SEND_SMS = 0x04,
    MMI_CLOG_LT_TB_ID_SEND_MMS = 0x08,
    MMI_CLOG_LT_TB_ID_ALL_MSG = 0x0E,
    MMI_CLOG_LT_TB_ID_ALL = 0x0F,
    MMI_CLOG_LT_TB_ID_MAX_ITEM = 4
} mmi_clog_lt_tb_id_enum;

/*----------------------------------------------------------------------------*/
/* Structure                                                                  */
/*----------------------------------------------------------------------------*/

typedef struct
{
    mmi_clog_lt_id_enum lt_id;
    MMI_STR_ID str_id;
} mmi_clog_lt_title_struct;

typedef struct
{
    const mmi_clog_lt_title_struct *title[MMI_CLOG_LT_ID_MAX_NUM];
} mmi_clog_lt_title_tbl_struct;

typedef struct
{
    mmi_clog_lt_id_enum lt_id;
    U16 scrn_id;
    MMI_STR_ID str_id;
    MMI_IMG_ID img_id;
} mmi_clog_lt_tab_page_struct;

typedef struct
{
    U32 total_num;
    const mmi_clog_lt_tab_page_struct *page[MMI_CLOG_LT_ID_MAX_NUM];
    MMI_CLOG_LT_TAB_HDLR page_hdlr;
} mmi_clog_lt_tab_struct;

#ifdef __MMI_FTE_SUPPORT__
typedef struct
{
    mmi_clog_lt_tb_id_enum tb_id;
    MMI_IMG_ID enb_img_id;
    MMI_IMG_ID dis_img_id;
    MMI_STR_ID str_id;
} mmi_clog_lt_tb_item_struct;

typedef struct
{
    U32 total_num;
    const mmi_clog_lt_tb_item_struct *items;
    MMI_CLOG_LT_TB_HDLR tb_hdlr;
} mmi_clog_lt_tb_struct;

typedef struct
{
    const mmi_clog_lt_tb_struct *tb;
    MMI_CLOG_LT_TAP_HDLR tap_hdlr;
} mmi_clog_lt_fte_struct;
#endif /* __MMI_FTE_SUPPORT__ */ 

typedef struct
{
    MMI_CLOG_LT_GET_ITEM_HDLR item_hdlr;
    MMI_CLOG_LT_GET_HINT_HDLR hint_hdlr;
} mmi_clog_lt_data_hdlr_tbl_struct;

typedef struct
{
    MMI_MENU_ID root_menu_id;
    const mmi_clog_lt_title_tbl_struct *title_tbl;
    const mmi_clog_key_tbl_struct *key_tbl;
    const mmi_clog_lt_img_tbl_struct *img_tbl;
    const mmi_clog_lt_tab_struct *tab;
    const mmi_clog_lt_data_hdlr_tbl_struct *hdlr_tbl;
#ifdef __MMI_FTE_SUPPORT__
    const mmi_clog_lt_fte_struct *fte;
#endif 
} mmi_clog_lt_scrn_data_struct;

typedef struct
{
    U32 total_num;
    U32 ur_mclt_num[SRV_CLOG_SIM_IDX_MAX_ITEM];
    mmi_clog_lt_id_num_info_struct id_nums[MMI_CLOG_LT_ID_MAX_NUM];
} mmi_clog_lt_id_num_tbl_struct;

typedef struct
{
    U32 total_num;
    SRV_CLOG_ID log_ids[SRV_CLOG_LOG_MAX_NUM];
} mmi_clog_lt_log_tbl_struct;

typedef struct
{
    SRV_CLOG_HANDLE handle;
    S32 srv_pid;
    mmi_clog_lt_id_num_tbl_struct num_tbl;  /* number info */
    mmi_clog_lt_log_tbl_struct log_tbl;     /* log id info */
} mmi_clog_lt_log_data_struct;

typedef struct
{
    U16 flags;
    mmi_clog_lt_type_enum lt_type;
    mmi_clog_lt_id_enum sel_lt_id;
    U16 sel_log_idx[MMI_CLOG_LT_ID_MAX_ITEM];
    SRV_CLOG_ID sel_log_id[MMI_CLOG_LT_ID_MAX_ITEM];
    MMI_ID self_gid;
    MMI_ID vr_gid;
    mmi_clog_lt_log_data_struct log_data;
} mmi_clog_lt_inst_struct;

typedef struct
{
    U8 is_init;
    mmi_clog_lt_inst_struct inst_list[MMI_CLOG_LT_INST_MAX_NUM];
} mmi_clog_lt_cntx_struct;

/*----------------------------------------------------------------------------*/
/* Static Function Declaration                                                */
/*----------------------------------------------------------------------------*/
/* Instance operations */
static mmi_clog_lt_cntx_struct *mmi_clog_lt_init_cntx(void);
static mmi_clog_lt_cntx_struct *mmi_clog_lt_get_cntx(void);
static void mmi_clog_lt_reset_inst(mmi_clog_lt_inst_struct *inst);
static void mmi_clog_lt_destroy_inst(mmi_clog_lt_inst_struct *inst);
static void mmi_clog_lt_reset_num_tbl(mmi_clog_lt_inst_struct *inst);
static mmi_clog_lt_inst_struct *mmi_clog_lt_alloc_inst(mmi_clog_lt_cntx_struct *cntx);
static mmi_clog_lt_inst_struct *mmi_clog_lt_get_inst_by_gid(mmi_clog_lt_cntx_struct *cntx, MMI_ID self_gid);

static MMI_STR_ID mmi_clog_lt_get_title_by_lt_id(mmi_clog_lt_inst_struct *inst, mmi_clog_lt_id_enum lt_id);
static MMI_IMG_ID mmi_clog_lt_get_img_by_idt(mmi_clog_lt_inst_struct *inst, const srv_clog_log_identity_struct *idt);
static mmi_clog_lt_id_num_info_struct *mmi_clog_lt_get_num_info_by_lt_id(
                                        mmi_clog_lt_inst_struct *inst,
                                        mmi_clog_lt_id_enum lt_id);
static void mmi_clog_lt_update_sel_log_id(mmi_clog_lt_inst_struct *inst);

/* Screen showing */
static MMI_RET mmi_clog_lt_group_proc(mmi_event_struct *evt);
static void mmi_clog_lt_refresh_int(mmi_clog_lt_inst_struct *inst);

static void mmi_clog_lt_enter(mmi_clog_lt_inst_struct *inst);
static void mmi_clog_lt_first_enter_list(mmi_clog_lt_inst_struct *inst);
static void mmi_clog_lt_enter_list(mmi_scrn_essential_struct *grp_data);
static void mmi_clog_lt_show_list(mmi_clog_lt_inst_struct *inst);
static void mmi_clog_lt_exit_list(mmi_scrn_essential_struct *grp_data);
static void mmi_clog_lt_send_exit_evt(mmi_clog_lt_inst_struct *inst);

#ifdef __MMI_CLOG_TAB_SUPPORT__
static void mmi_clog_lt_first_enter_tab(mmi_clog_lt_inst_struct *inst);
static void mmi_clog_lt_enter_tab(mmi_scrn_essential_struct *grp_data);
static void mmi_clog_lt_exit_tab(mmi_scrn_essential_struct *grp_data);
static void mmi_clog_lt_fill_tab_info(mmi_clog_lt_inst_struct *inst, mmi_frm_tab_struct *page_info, U32 page_num);
static void mmi_clog_lt_enter_tab_page(mmi_scrn_essential_struct *grp_data);
static void mmi_clog_lt_exit_tab_page(mmi_scrn_essential_struct *scr_info);
static void mmi_clog_lt_show_tab_page(mmi_clog_lt_inst_struct *inst);
static const mmi_clog_lt_tab_page_struct *mmi_clog_lt_get_page_by_lt_id(
                                            mmi_clog_lt_inst_struct *inst,
                                            mmi_clog_lt_id_enum lt_id);
static S32 mmi_clog_lt_get_page_index_by_lt_id(mmi_clog_lt_inst_struct *inst, mmi_clog_lt_id_enum lt_id);

#endif /* __MMI_CLOG_TAB_SUPPORT__ */ 

static void mmi_clog_lt_pre_enter(mmi_clog_lt_inst_struct *inst);
static pBOOL mmi_clog_lt_get_log_item(S32 item_index, UI_string_type str_buff, U8 **img_buff_p, U8 str_img_mask);
static void mmi_clog_lt_get_string(mmi_clog_lt_inst_struct *inst, srv_clog_log_struct *log, WCHAR *str_buff);
static S32 mmi_clog_lt_get_log_hint(S32 item_index, UI_string_type *hint_array);

/* Screen handlers */
static void mmi_clog_lt_item_hlt_hdlr(S32 sel);
static void mmi_clog_lt_set_key_hdlr(mmi_clog_lt_inst_struct *inst);
static void mmi_clog_lt_set_csk_key(S32 is_predef);

static void mmi_clog_lt_lsk_hdlr(void);
static void mmi_clog_lt_rsk_hdlr(void);
static void mmi_clog_lt_csk_hdlr(void);
static void mmi_clog_lt_ip_key_hdlr(void);
static void mmi_clog_lt_send_key_hdlr(void);

/* FTE operations */
#ifdef __MMI_FTE_SUPPORT__
static void mmi_clog_lt_tb_create(mmi_clog_lt_inst_struct *inst);
static void mmi_clog_lt_tb_refresh(mmi_clog_lt_inst_struct *inst);
static void mmi_clog_lt_tb_action_hdlr(S32 index);
static const mmi_clog_lt_tb_item_struct *mmi_clog_lt_get_tb_item_by_index(mmi_clog_lt_inst_struct *inst, S32 index);
static U32 mmi_clog_lt_tb_get_enb_items(mmi_clog_lt_inst_struct *inst);
static void mmi_clog_lt_set_tap_hdlr(mmi_clog_lt_inst_struct *inst);
static void mmi_clog_lt_tb_set_enb_state(mmi_clog_lt_inst_struct *inst, mmi_clog_lt_tb_id_enum ids, S32 enable);
static void mmi_clog_lt_tap_action_hdlr(mmi_tap_type_enum tap_type, S32 index);
#endif /* __MMI_FTE_SUPPORT__ */ 

static void mmi_clog_lt_op_enter(void);
static void mmi_clog_lt_viewer_enter(void);
static MMI_ID mmi_clog_lt_act_proc(mmi_clog_op_mid_enum op_mid, U32 flags);

/* Service access */
static void mmi_clog_lt_log_start(mmi_clog_lt_inst_struct *inst);
static void mmi_clog_lt_refresh_data(mmi_clog_lt_inst_struct *inst);
static void mmi_clog_lt_update_read_status(mmi_clog_lt_inst_struct *inst);
static void mmi_clog_lt_refresh_sel_index(mmi_clog_lt_inst_struct *inst);
static void mmi_clog_lt_refresh_screen(mmi_clog_lt_inst_struct *inst);
static S32 mmi_clog_lt_is_scrn_in_active(mmi_clog_lt_inst_struct *inst);
static void mmi_clog_lt_load_num(mmi_clog_lt_inst_struct *inst);
static void mmi_clog_lt_load_log_ids(mmi_clog_lt_inst_struct *inst);

static void mmi_clog_lt_inst_srv_evt_hdlr(mmi_clog_lt_inst_struct *inst, mmi_event_struct *evt);
static void mmi_clog_lt_inst_srv_evt_add_log_hdlr(mmi_clog_lt_inst_struct *inst, mmi_event_struct *evt);
static void mmi_clog_lt_srv_evt_refresh_hdlr(mmi_clog_lt_inst_struct *inst, srv_clog_evt_refresh_struct *evt);

/*----------------------------------------------------------------------------*/
/* Static Global Variable                                                     */
/*----------------------------------------------------------------------------*/
static const mmi_clog_lt_title_struct g_mmi_clog_lt_dialed_call = 
{
    MMI_CLOG_LT_ID_DIALED_CALL,
    STR_GLOBAL_DIALLED_CALLS
};

static const mmi_clog_lt_title_struct g_mmi_clog_lt_missed_call = 
{
    MMI_CLOG_LT_ID_MISSED_CALL,
    STR_GLOBAL_MISSED_CALLS
};

static const mmi_clog_lt_title_struct g_mmi_clog_lt_recved_call = 
{
    MMI_CLOG_LT_ID_RECVED_CALL,
    STR_GLOBAL_RECEIVED_CALLS
};

static const mmi_clog_lt_title_struct g_mmi_clog_lt_all_call = 
{
    MMI_CLOG_LT_ID_ALL_CALL,
    STR_ID_CLOG_ALL_CALL
};

static const mmi_clog_lt_title_tbl_struct g_mmi_clog_lt_title_tbl = 
{
    {
        &g_mmi_clog_lt_dialed_call,
        &g_mmi_clog_lt_missed_call,
        &g_mmi_clog_lt_recved_call,
        &g_mmi_clog_lt_all_call
    }
};

static const mmi_clog_key_tbl_struct g_mmi_clog_lt_key_tbl = 
{
    {
        &g_mmi_clog_lsk_option,
        &g_mmi_clog_csk_common,
        &g_mmi_clog_rsk_back
    },
    {
        mmi_clog_lt_lsk_hdlr,
        mmi_clog_lt_csk_hdlr,
        mmi_clog_lt_rsk_hdlr,
        mmi_clog_lt_ip_key_hdlr,
        mmi_clog_lt_send_key_hdlr,
     }
};

#ifdef __MMI_CLOG_TAB_SUPPORT__
static const mmi_clog_lt_tab_page_struct g_mmi_clog_lt_tab_page_dialed_call = 
{
    MMI_CLOG_LT_ID_DIALED_CALL,
    SCR_ID_CLOG_DIALED_CALL,
    STR_GLOBAL_DIALLED_CALLS,
    IMG_ID_CLOG_TAB_DIALED_CALL
};

static const mmi_clog_lt_tab_page_struct g_mmi_clog_lt_tab_page_missed_call = 
{
    MMI_CLOG_LT_ID_MISSED_CALL,
    SCR_ID_CLOG_MISSED_CALL,
    STR_GLOBAL_MISSED_CALLS,
    IMG_ID_CLOG_TAB_MISSED_CALL
};

static const mmi_clog_lt_tab_page_struct g_mmi_clog_lt_tab_page_recved_call = 
{
    MMI_CLOG_LT_ID_RECVED_CALL,
    SCR_ID_CLOG_RECVED_CALL,
    STR_GLOBAL_RECEIVED_CALLS,
    IMG_ID_CLOG_TAB_RECVED_CALL
};

static const mmi_clog_lt_tab_page_struct g_mmi_clog_lt_tab_page_all_call = 
{
    MMI_CLOG_LT_ID_ALL_CALL,
    SCR_ID_CLOG_ALL_CALL,
    STR_ID_CLOG_ALL_CALL,
    IMG_ID_CLOG_TAB_ALL_CALL
};

static const mmi_clog_lt_tab_struct g_mmi_clog_lt_tab = 
{
    4,
    {
        &g_mmi_clog_lt_tab_page_dialed_call,
        &g_mmi_clog_lt_tab_page_missed_call,
        &g_mmi_clog_lt_tab_page_recved_call,
        &g_mmi_clog_lt_tab_page_all_call
    },
    (MMI_CLOG_LT_TAB_HDLR) mmi_clog_lt_enter_tab_page
};

#endif /* __MMI_CLOG_TAB_SUPPORT__ */ 

#ifdef __MMI_FTE_SUPPORT__

/* The FTE toolbar show its items in the same order of the declarations in this array  */
static const mmi_clog_lt_tb_item_struct g_mmi_clog_lt_tb_item_list[] = 
{
    /* Make call */
    {
        MMI_CLOG_LT_TB_ID_MAKE_CALL,
        IMG_GLOBAL_TOOLBAR_CALL,
        IMG_GLOBAL_TOOLBAR_CALL_DISABLED,
        STR_GLOBAL_DIAL
    },
#ifdef __MMI_UNIFIED_COMPOSER__
    /* Send message */
    {
        MMI_CLOG_LT_TB_ID_SEND_MSG,
        IMG_GLOBAL_TOOLBAR_SEND_MESSAGE,
        IMG_GLOBAL_TOOLBAR_SEND_MESSAGE_DISABLED,
        STR_GLOBAL_SEND_MESSAGE
    },
#else /* __MMI_UNIFIED_COMPOSER__ */ 
    /* Send SMS */
    {
        MMI_CLOG_LT_TB_ID_SEND_SMS,
        IMG_ID_CLOG_TB_SEND_SMS,
        IMG_ID_CLOG_TB_SEND_SMS_DISABLE,
        STR_GLOBAL_SEND_TEXT_MESSAGE
    },

#ifdef __MMI_MMS__
    /* Send MMS */
    {
        MMI_CLOG_LT_TB_ID_SEND_MMS,
        IMG_ID_CLOG_TB_SEND_MMS,
        IMG_ID_CLOG_TB_SEND_MMS_DISABLE,
        STR_GLOBAL_SEND_MULTIMEDIA_MESSAGE
    }
#endif /* __MMI_MMS__ */ 
#endif /* __MMI_UNIFIED_COMPOSER__ */ 
};

static const mmi_clog_lt_tb_struct g_mmi_clog_lt_tb = 
{
    sizeof(g_mmi_clog_lt_tb_item_list) / sizeof(mmi_clog_lt_tb_item_struct),
    g_mmi_clog_lt_tb_item_list,
    mmi_clog_lt_tb_action_hdlr
};

static const mmi_clog_lt_fte_struct g_mmi_clog_lt_fte = 
{
    &g_mmi_clog_lt_tb,
    mmi_clog_lt_tap_action_hdlr,
};

#endif /* __MMI_FTE_SUPPORT__ */ 

static const mmi_clog_lt_data_hdlr_tbl_struct g_mmi_clog_lt_data_hdlr_tbl = 
{
    mmi_clog_lt_get_log_item,
    mmi_clog_lt_get_log_hint
};

static const mmi_clog_lt_scrn_data_struct g_mmi_clog_lt_scrn_data = 
{
    MAIN_MENU_CALL_LOG,
    &g_mmi_clog_lt_title_tbl,
    &g_mmi_clog_lt_key_tbl,
    &g_mmi_clog_lt_img_tbl,
#ifdef __MMI_CLOG_TAB_SUPPORT__
    &g_mmi_clog_lt_tab,
#else 
    NULL,
#endif 
    &g_mmi_clog_lt_data_hdlr_tbl,
#ifdef __MMI_FTE_SUPPORT__
    &g_mmi_clog_lt_fte
#endif 
};

static mmi_clog_lt_cntx_struct g_mmi_clog_lt_cntx;

/*----------------------------------------------------------------------------*/
/* Extern Function Defines                                                    */
/*----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------*/
/* Function Definition                                                        */
/*----------------------------------------------------------------------------*/

#define MMI_CLOG_LT_INIT


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_init_cntx
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  
 *****************************************************************************/
static mmi_clog_lt_cntx_struct *mmi_clog_lt_init_cntx(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U32 i;
    mmi_clog_lt_inst_struct *inst;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_mmi_clog_lt_cntx.is_init)
        return &g_mmi_clog_lt_cntx;

    for (i = 0; i < MMI_CLOG_LT_INST_MAX_NUM; i++)
    {
        inst = &g_mmi_clog_lt_cntx.inst_list[i];
        mmi_clog_lt_reset_inst(inst);
    }
    g_mmi_clog_lt_cntx.is_init = MMI_TRUE;
    return &g_mmi_clog_lt_cntx;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_get_cntx
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  
 *****************************************************************************/
static mmi_clog_lt_cntx_struct *mmi_clog_lt_get_cntx(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    return &g_mmi_clog_lt_cntx;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_reset_inst
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_reset_inst(mmi_clog_lt_inst_struct *inst)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    memset(inst, 0x0, sizeof(mmi_clog_lt_inst_struct));

    /* reset number table */
    mmi_clog_lt_reset_num_tbl(inst);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_destroy_inst
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_destroy_inst(mmi_clog_lt_inst_struct *inst)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!MMI_CLOG_IS_INST_VALID(inst, MMI_CLOG_INST_TYPE_LT))
        return;

    MMI_TRACE(
        MMI_CLOG_TRC_INFO,
        TRC_MMI_CLOG_LT_DESTROY_INST,
        inst->self_gid,
        inst->flags,
        inst->lt_type,
        inst->sel_lt_id,
        inst->sel_log_idx[inst->sel_lt_id],
        inst->sel_log_id[inst->sel_lt_id]);

    if (!MMI_CLOG_CHECK_BIT(inst->flags, MMI_CLOG_CMN_INST_FLAG_EXT_HANDLE))
        srv_clog_destroy(inst->log_data.handle);
    mmi_clog_lt_reset_inst(inst);

}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_reset_num_tbl
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_reset_num_tbl(mmi_clog_lt_inst_struct *inst)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U32 i;
    mmi_clog_lt_id_num_tbl_struct *num_tbl = &inst->log_data.num_tbl;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    for (i = 0; i < g_mmi_clog_lt_enb_ids.total_num; i++)
    {
        num_tbl->id_nums[i].lt_id = g_mmi_clog_lt_enb_ids.lt_ids[i];
    }
    num_tbl->total_num = g_mmi_clog_lt_enb_ids.total_num;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_alloc_inst
 * DESCRIPTION
 *  
 * PARAMETERS
 *  cntx        [IN]     
 * RETURNS
 *  
 *****************************************************************************/
static mmi_clog_lt_inst_struct *mmi_clog_lt_alloc_inst(mmi_clog_lt_cntx_struct *cntx)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U32 i;
    mmi_clog_lt_inst_struct *inst;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    for (i = 0; i < MMI_CLOG_LT_INST_MAX_NUM; i++)
    {
        inst = &cntx->inst_list[i];
        if (!MMI_CLOG_CHECK_BIT(inst->flags, MMI_CLOG_CMN_INST_FLAG_IS_USED))
        {
            MMI_CLOG_SET_BIT(inst->flags, MMI_CLOG_CMN_INST_FLAG_IS_USED | MMI_CLOG_INST_TYPE_LT);
            return inst;
        }
    }
    return NULL;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_get_inst_by_gid
 * DESCRIPTION
 *  
 * PARAMETERS
 *  cntx            [IN]         
 *  self_gid        [IN]        
 * RETURNS
 *  
 *****************************************************************************/
static mmi_clog_lt_inst_struct *mmi_clog_lt_get_inst_by_gid(mmi_clog_lt_cntx_struct *cntx, MMI_ID self_gid)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U32 i;
    mmi_clog_lt_inst_struct *inst;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    for (i = 0; i < MMI_CLOG_LT_INST_MAX_NUM; i++)
    {
        inst = &cntx->inst_list[i];

        if (!MMI_CLOG_IS_INST_VALID(inst, MMI_CLOG_INST_TYPE_LT))
            continue;
        if (inst->self_gid == self_gid)
            return inst;
    }
    return NULL;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_get_title_by_lt_id
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]         
 *  lt_id       [IN]        
 * RETURNS
 *  
 *****************************************************************************/
static MMI_STR_ID mmi_clog_lt_get_title_by_lt_id(mmi_clog_lt_inst_struct *inst, mmi_clog_lt_id_enum lt_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U32 i;
    const mmi_clog_lt_title_tbl_struct *title_tbl = g_mmi_clog_lt_scrn_data.title_tbl;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!title_tbl)
        return 0;

    if (lt_id < MMI_CLOG_LT_ID_MAX_NUM && title_tbl->title[lt_id] && title_tbl->title[lt_id]->lt_id == lt_id)
    {
        return title_tbl->title[lt_id]->str_id;
    }
    for (i = 0; i < MMI_CLOG_LT_ID_MAX_NUM; i++)
    {
        if (title_tbl->title[i] && title_tbl->title[i]->lt_id == lt_id)
            return title_tbl->title[i]->str_id;
    }
    MMI_ASSERT(!"Wrong lt_id");
    return 0;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_get_img_by_idt
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]         
 *  idt         [IN]        
 * RETURNS
 *  
 *****************************************************************************/
static MMI_IMG_ID mmi_clog_lt_get_img_by_idt(mmi_clog_lt_inst_struct *inst, const srv_clog_log_identity_struct *idt)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    return mmi_clog_get_image(idt);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_get_num_info_by_lt_id
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]         
 *  lt_id       [IN]        
 * RETURNS
 *  
 *****************************************************************************/
static mmi_clog_lt_id_num_info_struct *mmi_clog_lt_get_num_info_by_lt_id(
                                        mmi_clog_lt_inst_struct *inst,
                                        mmi_clog_lt_id_enum lt_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U32 i;
    mmi_clog_lt_id_num_tbl_struct *num_tbl = &inst->log_data.num_tbl;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if ((U32) lt_id < num_tbl->total_num && num_tbl->id_nums[lt_id].lt_id == lt_id)
        return &num_tbl->id_nums[lt_id];

    for (i = 0; i < num_tbl->total_num; i++)
    {
        if (num_tbl->id_nums[i].lt_id == lt_id)
            return &num_tbl->id_nums[i];
    }
    MMI_CLOG_ASSERT(!"Wrong lt_id");
    return NULL;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_update_sel_log_id
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_update_sel_log_id(mmi_clog_lt_inst_struct *inst)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    inst->sel_log_id[inst->sel_lt_id] = inst->log_data.log_tbl.log_ids[inst->sel_log_idx[inst->sel_lt_id]];
}

#define MMI_CLOG_LT_IF


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_init_para
 * DESCRIPTION
 *  
 * PARAMETERS
 *  create      [IN]     
 * RETURNS
 *  
 *****************************************************************************/
MMI_RET mmi_clog_lt_init_para(mmi_clog_lt_create_struct *create)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!create)
        return MMI_RET_ERR;
    memset(create, 0x0, sizeof(mmi_clog_lt_create_struct));
    return MMI_RET_OK;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_create
 * DESCRIPTION
 *  
 * PARAMETERS
 *  parent_gid      [IN]        
 *  create          [IN]        
 * RETURNS
 *  
 *****************************************************************************/
MMI_ID mmi_clog_lt_create(MMI_ID parent_gid, const mmi_clog_lt_create_struct *create)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    MMI_ID gid;
    mmi_clog_lt_inst_struct *inst;
    mmi_clog_lt_cntx_struct *cntx = mmi_clog_lt_init_cntx();

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (MMI_CLOG_IS_GID_INVALID(parent_gid))
    {
        MMI_ASSERT(!"wrong parent_id");
        return 0;
    }
    if (!create || create->lt_type >= MMI_CLOG_LT_TYPE_MAX_ITEM)
    {
        MMI_ASSERT(!"invalid_ para");
        return 0;
    }

    inst = mmi_clog_lt_alloc_inst(cntx);
    if (!inst)
    {
        MMI_ASSERT(!"No inst");
        return 0;
    }
    inst->lt_type = create->lt_type;
    inst->log_data.handle = create->handle;
    if (!SRV_CLOG_IS_ELM_INVALID(create->handle))
        MMI_CLOG_SET_BIT(inst->flags, MMI_CLOG_CMN_INST_FLAG_EXT_HANDLE);
    mmi_clog_lt_log_start(inst);

    gid = mmi_clog_alloc_gid(MMI_CLOG_GRP_TYPE_LT);
    inst->self_gid = mmi_frm_group_create(parent_gid, gid, mmi_clog_lt_group_proc, inst);

    MMI_TRACE(
        MMI_CLOG_TRC_INFO,
        TRC_MMI_CLOG_LT_CREATE,
        parent_gid,
        inst->self_gid,
        create->lt_type,
        inst->flags,
        create->handle,
        inst->log_data.handle);

    return inst->self_gid;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_run
 * DESCRIPTION
 *  
 * PARAMETERS
 *  lt_gid      [IN]        
 * RETURNS
 *  
 *****************************************************************************/
MMI_RET mmi_clog_lt_run(MMI_ID lt_gid)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_clog_lt_inst_struct *inst;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    inst = mmi_clog_lt_get_inst_by_gid(mmi_clog_lt_get_cntx(), lt_gid);
    if (!inst)
        return MMI_RET_ERR;
    /* first time to load ids */

    mmi_frm_group_enter(inst->self_gid, MMI_FRM_NODE_SMART_CLOSE_FLAG);
    mmi_clog_lt_enter(inst);
    return MMI_RET_OK;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_close
 * DESCRIPTION
 *  
 * PARAMETERS
 *  lt_gid      [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_clog_lt_close(MMI_ID lt_gid)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_clog_lt_inst_struct *inst;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    inst = mmi_clog_lt_get_inst_by_gid(mmi_clog_lt_get_cntx(), lt_gid);
    if (!inst)
        return;
    mmi_frm_group_close(inst->self_gid);
    return;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_set_sel_lt_id
 * DESCRIPTION
 *  
 * PARAMETERS
 *  lt_gid      [IN]        
 *  lt_id       [IN]        
 * RETURNS
 *  
 *****************************************************************************/
MMI_RET mmi_clog_lt_set_sel_lt_id(MMI_ID lt_gid, mmi_clog_lt_id_enum lt_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_clog_lt_inst_struct *inst;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (MMI_CLOG_IS_GID_INVALID(lt_gid) || lt_id >= MMI_CLOG_LT_ID_MAX_ITEM)
        return MMI_RET_ERR;

    inst = mmi_clog_lt_get_inst_by_gid(mmi_clog_lt_get_cntx(), lt_gid);
    if (!inst)
        return MMI_RET_ERR;

    MMI_TRACE(MMI_CLOG_TRC_INFO, TRC_MMI_CLOG_LT_SET_SEL_LT_ID, lt_gid, lt_id);
    MMI_CLOG_ASSERT(lt_id < MMI_CLOG_LT_ID_MAX_ITEM);
    inst->sel_lt_id = lt_id;
    inst->sel_log_idx[lt_id] = 0;
    mmi_clog_lt_update_sel_log_id(inst);
    return MMI_RET_OK;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_refresh
 * DESCRIPTION
 *  
 * PARAMETERS
 *  lt_gid      [IN]        
 * RETURNS
 *  
 *****************************************************************************/
MMI_RET mmi_clog_lt_refresh(MMI_ID lt_gid)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_clog_lt_inst_struct *inst;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    inst = mmi_clog_lt_get_inst_by_gid(mmi_clog_lt_get_cntx(), lt_gid);
    if (!inst)
        return MMI_RET_ERR;
    mmi_clog_lt_refresh_int(inst);
    return MMI_RET_OK;
}

#define MMI_CLOG_LT_GRP


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_group_proc
 * DESCRIPTION
 *  
 * PARAMETERS
 *  evt     [IN]     
 * RETURNS
 *  
 *****************************************************************************/
static MMI_RET mmi_clog_lt_group_proc(mmi_event_struct *evt)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_clog_lt_inst_struct *inst;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    inst = (mmi_clog_lt_inst_struct*) evt->user_data;

    switch (evt->evt_id)
    {
        case EVT_ID_GROUP_FIRST_ENTRY:
            break;

        case EVT_ID_GROUP_ACTIVE:
            break;

        case EVT_ID_GROUP_INACTIVE:
            break;

        case EVT_ID_GROUP_DEINIT:
            mmi_clog_lt_destroy_inst(inst);
            break;

        case EVT_ID_MMI_CLOG_VR_EXIT:
            mmi_clog_vr_close(inst->vr_gid);
            inst->vr_gid = GRP_ID_INVALID;
            break;

        default:
            break;
    }
    return MMI_RET_OK;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_refresh_int
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_refresh_int(mmi_clog_lt_inst_struct *inst)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_clog_lt_refresh_data(inst);
    mmi_clog_lt_refresh_screen(inst);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_refresh_screen
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_refresh_screen(mmi_clog_lt_inst_struct *inst)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!mmi_clog_lt_is_scrn_in_active(inst))
        return;
    mmi_frm_display_dummy_screen();
    mmi_frm_scrn_close_active_id();
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_is_scrn_in_active
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]     
 * RETURNS
 *  
 *****************************************************************************/
static S32 mmi_clog_lt_is_scrn_in_active(mmi_clog_lt_inst_struct *inst)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (mmi_clog_is_scrn_in_active(inst->self_gid, SCR_ID_CLOG_LAYOUT) ||
        mmi_clog_is_scrn_in_active(inst->self_gid, SCR_ID_CLOG_DIALED_CALL) ||
        mmi_clog_is_scrn_in_active(inst->self_gid, SCR_ID_CLOG_MISSED_CALL) ||
        mmi_clog_is_scrn_in_active(inst->self_gid, SCR_ID_CLOG_RECVED_CALL) ||
        mmi_clog_is_scrn_in_active(inst->self_gid, SCR_ID_CLOG_ALL_CALL))
        return MMI_TRUE;
    return MMI_FALSE;
}

#define MMI_CLOG_LT_UI


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_enter
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_enter(mmi_clog_lt_inst_struct *inst)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    switch (inst->lt_type)
    {
        case MMI_CLOG_LT_TYPE_LIST:
            mmi_clog_lt_first_enter_list(inst);
            break;

    #ifdef __MMI_CLOG_TAB_SUPPORT__
        case MMI_CLOG_LT_TYPE_TAB:
            mmi_clog_lt_first_enter_tab(inst);
            /* mmi_clog_lt_enter_tab(); */
            break;
    #endif /* __MMI_CLOG_TAB_SUPPORT__ */ 

        default:
            MMI_ASSERT(!"Wrong lt_type");
            break;
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_first_enter_list
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_first_enter_list(mmi_clog_lt_inst_struct *inst)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_frm_scrn_first_enter(inst->self_gid, SCR_ID_CLOG_LAYOUT, (FuncPtr) mmi_clog_lt_enter_list, inst);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_enter_list
 * DESCRIPTION
 *  
 * PARAMETERS
 *  grp_data        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_enter_list(mmi_scrn_essential_struct *grp_data)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 ret;
    mmi_clog_lt_inst_struct *inst;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    inst = (mmi_clog_lt_inst_struct*) grp_data->user_data;
    ret = mmi_frm_scrn_enter(
            inst->self_gid,
            SCR_ID_CLOG_LAYOUT,
            (FuncPtr) mmi_clog_lt_exit_list,
            (FuncPtr) mmi_clog_lt_enter_list,
            MMI_FRM_UNKNOW_SCRN);
    if (!ret)
        return;

    mmi_clog_lt_refresh_data(inst);
    mmi_clog_lt_show_list(inst);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_show_list
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_show_list(mmi_clog_lt_inst_struct *inst)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 *gui_buffer;
    S32 has_lsk = MMI_FALSE;
    mmi_clog_lt_id_num_info_struct *num_info;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_clog_lt_pre_enter(inst);

    num_info = mmi_clog_lt_get_num_info_by_lt_id(inst, inst->sel_lt_id);
    if (num_info->num_info.num[SRV_CLOG_LOG_NUM_TYPE_TOTAL_LOGS])
        has_lsk = MMI_TRUE;

    gui_buffer = mmi_frm_scrn_get_active_gui_buf();
    if (MMI_CLOG_CHECK_BIT(inst->flags, MMI_CLOG_LT_FLAG_CUR_SEL_IDX_CHANGED))
    {
        gui_buffer = NULL;
        MMI_CLOG_CLEAR_BIT(inst->flags, MMI_CLOG_LT_FLAG_CUR_SEL_IDX_CHANGED);
    }

    RegisterHighlightHandler(mmi_clog_lt_item_hlt_hdlr);

    ShowCategory184Screen(
        mmi_clog_lt_get_title_by_lt_id(inst, inst->sel_lt_id),
        GetRootTitleIcon(g_mmi_clog_lt_scrn_data.root_menu_id),
        (MMI_STR_ID) (has_lsk == 0 ? 0 : g_mmi_clog_lt_scrn_data.key_tbl->softkey[MMI_CLOG_KEY_LSK]->str_id),
        (MMI_IMG_ID) (has_lsk == 0 ? 0 : g_mmi_clog_lt_scrn_data.key_tbl->softkey[MMI_CLOG_KEY_LSK]->img_id),
        g_mmi_clog_lt_scrn_data.key_tbl->softkey[MMI_CLOG_KEY_RSK]->str_id,
        g_mmi_clog_lt_scrn_data.key_tbl->softkey[MMI_CLOG_KEY_RSK]->img_id,
        inst->log_data.log_tbl.total_num,
        g_mmi_clog_lt_scrn_data.hdlr_tbl->item_hdlr,
        g_mmi_clog_lt_scrn_data.hdlr_tbl->hint_hdlr,
        inst->sel_log_idx[inst->sel_lt_id],
        gui_buffer);

    mmi_clog_lt_set_key_hdlr(inst);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_exit_list
 * DESCRIPTION
 *  
 * PARAMETERS
 *  grp_data        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_exit_list(mmi_scrn_essential_struct *grp_data)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_clog_lt_inst_struct *inst;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    inst = (mmi_clog_lt_inst_struct*) grp_data->user_data;
    mmi_clog_lt_send_exit_evt(inst);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_send_exit_evt
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_send_exit_evt(mmi_clog_lt_inst_struct *inst)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_clog_lt_evt_struct evt;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_FRM_INIT_GROUP_EVENT(&evt, EVT_ID_MMI_CLOG_LT_EXIST, inst->self_gid);

    MMI_FRM_INIT_EVENT(&evt, EVT_ID_MMI_CLOG_LT_EXIST);
    /* evt.user_data = inst->user_data; */
    mmi_frm_group_send_to_caller(inst->self_gid, (mmi_group_event_struct*) & evt);
}

#ifdef __MMI_CLOG_TAB_SUPPORT__


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_first_enter_tab
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_first_enter_tab(mmi_clog_lt_inst_struct *inst)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_frm_scrn_first_enter(inst->self_gid, SCR_ID_CLOG_LAYOUT, (FuncPtr) mmi_clog_lt_enter_tab, inst);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_enter_tab
 * DESCRIPTION
 *  
 * PARAMETERS
 *  scr_info        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_enter_tab(mmi_scrn_essential_struct *scr_info)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_clog_lt_inst_struct *inst;
    mmi_frm_tab_struct page_info[MMI_CLOG_LT_ID_MAX_NUM];

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    inst = (mmi_clog_lt_inst_struct *)scr_info->user_data;
    mmi_clog_lt_fill_tab_info(inst, page_info, MMI_CLOG_LT_ID_MAX_NUM);
    mmi_frm_scrn_tab_enter(
        inst->self_gid,
        SCR_ID_CLOG_LAYOUT,
        (FuncPtr) mmi_clog_lt_exit_tab,
        (FuncPtr) mmi_clog_lt_enter_tab,
        page_info,
        (U8) g_mmi_clog_lt_enb_ids.total_num,
        (U8) mmi_clog_lt_get_page_index_by_lt_id(inst, inst->sel_lt_id));
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_exit_tab
 * DESCRIPTION
 *  
 * PARAMETERS
 *  scr_info        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_exit_tab(mmi_scrn_essential_struct *scr_info)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* mmi_frm_general_tab_exit(); */
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_fill_tab_info
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst            [IN]         
 *  page_info       [OUT]         
 *  page_num        [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_fill_tab_info(mmi_clog_lt_inst_struct *inst, mmi_frm_tab_struct *page_info, U32 page_num)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U32 i;
    const mmi_clog_lt_tab_page_struct *page;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    for (i = 0; i < g_mmi_clog_lt_enb_ids.total_num && i < page_num; i++)
    {
        page = mmi_clog_lt_get_page_by_lt_id(inst, g_mmi_clog_lt_enb_ids.lt_ids[i]);
        page_info[i].screen_id = page->scrn_id;
        page_info[i].tab_icon = (U8*) GetImage(page->img_id);
        page_info[i].tab_string = NULL;
        page_info[i].tab_entry_func = g_mmi_clog_lt_scrn_data.tab->page_hdlr;
        page_info[i].user_data = inst;
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_enter_tab_page
 * DESCRIPTION
 *  
 * PARAMETERS
 *  grp_data        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_enter_tab_page(mmi_scrn_essential_struct *grp_data)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 ret;
    U32 index;
    mmi_clog_lt_inst_struct *inst;
    const mmi_clog_lt_tab_page_struct *page;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    inst = (mmi_clog_lt_inst_struct*) grp_data->user_data;
    index = mmi_frm_scrn_tab_get_active_page_index();
    MMI_ASSERT(index < g_mmi_clog_lt_enb_ids.total_num);
    inst->sel_lt_id = g_mmi_clog_lt_enb_ids.lt_ids[index];

    page = mmi_clog_lt_get_page_by_lt_id(inst, inst->sel_lt_id);
    ret = mmi_frm_scrn_tab_page_enter(
            inst->self_gid,
            SCR_ID_CLOG_LAYOUT,
            page->scrn_id,
            (FuncPtr) mmi_clog_lt_exit_tab_page,
            (FuncPtr) mmi_clog_lt_enter_tab_page,
            MMI_FRM_TAB_PAGE);
    if (!ret)
        return;

    /* Reload log data after change select lt_id */
    mmi_clog_lt_refresh_data(inst);

    mmi_clog_lt_show_tab_page(inst);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_exit_tab_page
 * DESCRIPTION
 *  
 * PARAMETERS
 *  scr_info        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_exit_tab_page(mmi_scrn_essential_struct *scr_info)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_show_tab_page
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_show_tab_page(mmi_clog_lt_inst_struct *inst)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 *gui_buff;
    const mmi_clog_lt_tab_page_struct *page;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_clog_lt_pre_enter(inst);

    page = mmi_clog_lt_get_page_by_lt_id(inst, inst->sel_lt_id);
    gui_buff = mmi_frm_scrn_tab_page_get_active_gui_buf();
    if (MMI_CLOG_CHECK_BIT(inst->flags, MMI_CLOG_LT_FLAG_CUR_SEL_IDX_CHANGED))
    {
        gui_buff = NULL;
        MMI_CLOG_CLEAR_BIT(inst->flags, MMI_CLOG_LT_FLAG_CUR_SEL_IDX_CHANGED);
    }
    RegisterHighlightHandler(mmi_clog_lt_item_hlt_hdlr);

    ShowCategory629Screen(
        mmi_clog_lt_get_title_by_lt_id(inst, inst->sel_lt_id),
        page->img_id,
        g_mmi_clog_lt_scrn_data.key_tbl->softkey[MMI_CLOG_KEY_LSK]->str_id,
        g_mmi_clog_lt_scrn_data.key_tbl->softkey[MMI_CLOG_KEY_LSK]->img_id,
        g_mmi_clog_lt_scrn_data.key_tbl->softkey[MMI_CLOG_KEY_RSK]->str_id,
        g_mmi_clog_lt_scrn_data.key_tbl->softkey[MMI_CLOG_KEY_RSK]->img_id,
        (S32) inst->log_data.log_tbl.total_num,
        g_mmi_clog_lt_scrn_data.hdlr_tbl->item_hdlr,
        g_mmi_clog_lt_scrn_data.hdlr_tbl->hint_hdlr,
        inst->sel_log_idx[inst->sel_lt_id],
        mmi_clog_lt_get_page_index_by_lt_id(inst, inst->sel_lt_id),
        gui_buff);

    mmi_clog_lt_set_key_hdlr(inst);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_get_page_by_lt_id
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]         
 *  lt_id       [IN]        
 * RETURNS
 *  
 *****************************************************************************/
static const mmi_clog_lt_tab_page_struct *mmi_clog_lt_get_page_by_lt_id(
                                            mmi_clog_lt_inst_struct *inst,
                                            mmi_clog_lt_id_enum lt_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U32 i;
    const mmi_clog_lt_tab_struct *tab = g_mmi_clog_lt_scrn_data.tab;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!tab || !tab->page)
        return NULL;

    if ((U32) lt_id < tab->total_num && tab->page[lt_id] && tab->page[lt_id]->lt_id == lt_id)
    {
        return tab->page[lt_id];
    }

    for (i = 0; i < MMI_CLOG_LT_ID_MAX_NUM; i++)
    {
        if (tab->page[i] && tab->page[i]->lt_id == lt_id)
            return tab->page[i];
    }
    MMI_ASSERT(!"wrong lt_id");
    return NULL;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_get_page_index_by_lt_id
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]         
 *  lt_id       [IN]        
 * RETURNS
 *  
 *****************************************************************************/
static S32 mmi_clog_lt_get_page_index_by_lt_id(mmi_clog_lt_inst_struct *inst, mmi_clog_lt_id_enum lt_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U32 i;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if ((U32) lt_id < g_mmi_clog_lt_enb_ids.total_num && g_mmi_clog_lt_enb_ids.lt_ids[lt_id] == lt_id)
        return lt_id;

    for (i = 0; i < g_mmi_clog_lt_enb_ids.total_num; i++)
    {
        if (g_mmi_clog_lt_enb_ids.lt_ids[i] == lt_id)
            return i;
    }
    MMI_ASSERT(!"Wrong lt_id");
    return 0;
}

#endif /* __MMI_CLOG_TAB_SUPPORT__ */ 


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_pre_enter
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_pre_enter(mmi_clog_lt_inst_struct *inst)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#ifdef __MMI_FTE_SUPPORT__
    mmi_clog_lt_tb_create(inst);
    mmi_clog_lt_tb_refresh(inst);
#endif /* __MMI_FTE_SUPPORT__ */ 
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_get_log_item
 * DESCRIPTION
 *  
 * PARAMETERS
 *  item_index          [IN]        
 *  str_buff            [IN]        
 *  img_buff_p          [IN]        
 *  str_img_mask        [IN]        
 * RETURNS
 *  
 *****************************************************************************/
static pBOOL mmi_clog_lt_get_log_item(S32 item_index, UI_string_type str_buff, U8 **img_buff_p, U8 str_img_mask)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 ret;
    mmi_clog_lt_inst_struct *inst;
    srv_clog_log_struct log;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    inst = (mmi_clog_lt_inst_struct*) mmi_clog_get_inst_by_act_gid();
    MMI_CLOG_ASSERT(MMI_CLOG_IS_INST_VALID(inst, MMI_CLOG_INST_TYPE_LT));

    if (item_index < 0 || item_index >= (S32) inst->log_data.log_tbl.total_num)
    {
        MMI_CLOG_ASSERT(item_index < (S32) inst->log_data.log_tbl.total_num);
        return MMI_FALSE;
    }
    ret = srv_clog_get_log_by_id(inst->log_data.handle, inst->log_data.log_tbl.log_ids[item_index], 0, &log);
    if (ret != SRV_CLOG_RET_OK)
    {
        str_buff[0] = '\0';
        *img_buff_p = NULL;
        return MMI_FALSE;
    }
    mmi_clog_lt_get_string(inst, &log, str_buff);
    *img_buff_p =
        (U8*) GetImage(mmi_clog_lt_get_img_by_idt(inst, (const srv_clog_log_identity_struct*)&log.data.call_log));
    return MMI_TRUE;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_get_string
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst            [IN]     
 *  log             [IN]     
 *  str_buff        [OUT]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_get_string(mmi_clog_lt_inst_struct *inst, srv_clog_log_struct *log, WCHAR *str_buff)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    WCHAR post[20];
    U32 post_len = 0;
    const WCHAR *unknown_cid;
    srv_clog_call_log_struct *call_log = &log->data.call_log;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (call_log->total_num > 1)
    {
        kal_wsprintf(post, " (%d)", call_log->total_num);
        post_len = mmi_wcslen(post);
    }
    if (mmi_clog_is_name_empty(log) && mmi_clog_is_cid_empty(log))
    {
        unknown_cid = (const WCHAR*)get_string(STR_ID_CLOG_UNKNOWN_NUMBER);
        mmi_clog_w_cpy((WCHAR*) str_buff, unknown_cid, MAX_SUBMENU_CHARACTERS);
    }
    else if (mmi_clog_is_name_empty(log))
    {
        mmi_clog_w_cpy((WCHAR*) str_buff, (const WCHAR*)call_log->cid, MAX_SUBMENU_CHARACTERS - post_len);
    }
    else
    {
        mmi_clog_w_cpy((WCHAR*) str_buff, (const WCHAR*)call_log->name, MAX_SUBMENU_CHARACTERS - post_len);
    }
    if (post_len)
        mmi_wcscat((WCHAR*) str_buff, (const WCHAR*)post);

#if defined(__MMI_DSM_NEW__) && defined( __HC_CALL_NEW__)
	{		
		U8 city_number[30];
		U8 counter_ucs2_city[30 * ENCODING_LENGTH];
		U8 counter_len_city = 0;
		S8 city_array[MAX_SUBMENU_CHARACTERS];
		memset(city_array,0,MAX_SUBMENU_CHARACTERS);
		mmi_ucs2_to_asc((char *)city_number,(char *)call_log->cid);
		counter_len_city = HcCall_hist_populate_call_list((char *)city_array,MAX_SUBMENU_CHARACTERS>>1,(char *)city_number);
		
		if(counter_len_city && ((mmi_ucs2strlen((S8*)str_buff)+counter_len_city) <MAX_SUBMENU_CHARACTERS))
		{
			mmi_ucs2cat((S8*)str_buff, (PS8) city_array);
		}

	}
#endif

}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_get_log_hint
 * DESCRIPTION
 *  
 * PARAMETERS
 *  item_index      [IN]        
 *  hint_array      [OUT]         
 * RETURNS
 *  
 *****************************************************************************/
static S32 mmi_clog_lt_get_log_hint(S32 item_index, UI_string_type *hint_array)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 ret;
    mmi_clog_lt_inst_struct *inst;
    srv_clog_log_struct log;
    applib_time_struct app_time;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    inst = (mmi_clog_lt_inst_struct*) mmi_clog_get_inst_by_act_gid();
    MMI_CLOG_ASSERT(MMI_CLOG_IS_INST_VALID(inst, MMI_CLOG_INST_TYPE_LT));

    if (item_index < 0 || item_index >= (S32) inst->log_data.log_tbl.total_num)
    {
        /* MMI_CLOG_ASSERT(item_index < (S32) inst->log_data.log_tbl.total_num); */
        return MMI_FALSE;
    }
    ret = srv_clog_get_log_by_id(
            inst->log_data.handle,
            inst->log_data.log_tbl.log_ids[item_index],
            SRV_CLOG_LOG_FIELD_TIMESTAMP,
            &log);
    if (ret != SRV_CLOG_RET_OK)
    {
        hint_array[0] = '\0';
        return MMI_FALSE;
    }
    if (log.data.call_log.timestamp == 0)
    {
        hint_array[0][0] = '\0';
    }
    else
    {
        mmi_clog_time_utc2app(log.data.call_log.timestamp, &app_time);
        if (app_time.nDay != 0)
        {
            if (mmi_clog_is_today(&app_time))
            {
                time_string((UI_time*) & app_time, (UI_string_type) hint_array[0], DT_IDLE_SCREEN);
            }
            else
            {
                date_string((UI_time*) & app_time, (UI_string_type) hint_array[0], DT_IDLE_SCREEN);
            }
        }
        else
        {
            hint_array[0][0] = '\0';
            /* memset(hint_array[0], 0x00, ENCODING_LENGTH); */
        }
    }
    return MMI_TRUE;
}

#define MMI_CLOG_LT_HDLR


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_item_hlt_hdlr
 * DESCRIPTION
 *  
 * PARAMETERS
 *  sel     [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_item_hlt_hdlr(S32 sel)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_clog_lt_inst_struct *inst;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    inst = (mmi_clog_lt_inst_struct*) mmi_clog_get_inst_by_act_gid();
    MMI_CLOG_ASSERT(MMI_CLOG_IS_INST_VALID(inst, MMI_CLOG_INST_TYPE_LT));

    inst->sel_log_idx[inst->sel_lt_id] = sel;
    mmi_clog_lt_update_sel_log_id(inst);

#ifdef __MMI_FTE_SUPPORT__
    mmi_clog_lt_tb_refresh(inst);
#endif 
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_set_key_hdlr
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_set_key_hdlr(mmi_clog_lt_inst_struct *inst)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (inst->log_data.log_tbl.total_num)
    {
        mmi_ucm_handle_sendkeys_for_call(g_mmi_clog_lt_scrn_data.key_tbl->hdlr[MMI_CLOG_KEY_SEND], KEY_EVENT_DOWN);

    #ifdef __MMI_IP_KEY__
/* under construction !*/
    #endif 
    }

    if (inst->log_data.log_tbl.total_num != 0)
    {
        mmi_clog_lt_set_csk_key(MMI_TRUE);
        SetLeftSoftkeyFunction(g_mmi_clog_lt_scrn_data.key_tbl->hdlr[MMI_CLOG_KEY_LSK], KEY_EVENT_UP);
    }
    else
    {
        /* check if has advanced menu item */
#if (defined(__MMI_CLOG_CALL_TIME__) || defined(__MMI_CLOG_CALL_COST__) || defined(__MMI_CLOG_SMS_COUNT__) || defined(__MMI_CLOG_GPRS_COUNT__))
        if (inst->lt_type == MMI_CLOG_LT_TYPE_TAB)
        {
            mmi_clog_lt_set_csk_key(MMI_FALSE);
            SetLeftSoftkeyFunction(g_mmi_clog_lt_scrn_data.key_tbl->hdlr[MMI_CLOG_KEY_LSK], KEY_EVENT_UP);
        }
#endif
    }

    SetLeftSoftkeyFunction(g_mmi_clog_lt_scrn_data.key_tbl->hdlr[MMI_CLOG_KEY_LSK], KEY_EVENT_UP);

    SetRightSoftkeyFunction(g_mmi_clog_lt_scrn_data.key_tbl->hdlr[MMI_CLOG_KEY_RSK], KEY_EVENT_UP);

#ifdef __MMI_TOUCH_SCREEN__
    wgui_set_horizontal_tab_bar_select_callback(mmi_frm_set_cur_sel_page);
#endif 

#ifdef __MMI_FTE_SUPPORT__
    mmi_clog_lt_set_tap_hdlr(inst);
#endif 

#ifdef __MMI_CLOG_SIM_SYNC_TEST__
    {
        extern void srv_clog_sim_pwon_test(void);
        extern void srv_clog_sim_pwoff_test(void);
        extern void srv_clog_sim_sat_refresh_test(void);

        SetKeyHandler(srv_clog_sim_pwon_test, KEY_VOL_UP, KEY_EVENT_UP);
        SetKeyHandler(srv_clog_sim_pwoff_test, KEY_VOL_DOWN, KEY_EVENT_UP);
        SetKeyHandler(srv_clog_sim_sat_refresh_test, KEY_CAMERA, KEY_EVENT_UP);

        SetKeyHandler(srv_clog_sim_pwon_test, KEY_STAR, KEY_EVENT_UP);
        SetKeyHandler(srv_clog_sim_pwoff_test, KEY_POUND, KEY_EVENT_UP);
        SetKeyHandler(srv_clog_sim_sat_refresh_test, KEY_0, KEY_EVENT_UP);
    }

#endif /* __MMI_CLOG_SIM_SYNC_TEST__ */ 

}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_set_csk_key
 * DESCRIPTION
 *  
 * PARAMETERS
 *  is_predef       [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_set_csk_key(S32 is_predef)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (is_predef)
    {
        EnableCenterSoftkey(
            g_mmi_clog_lt_scrn_data.key_tbl->softkey[MMI_CLOG_KEY_CSK]->str_id,
            g_mmi_clog_lt_scrn_data.key_tbl->softkey[MMI_CLOG_KEY_CSK]->img_id);

        SetCenterSoftkeyFunction(g_mmi_clog_lt_scrn_data.key_tbl->hdlr[MMI_CLOG_KEY_CSK], KEY_EVENT_UP);
    }
    else
    {
        EnableCenterSoftkey(0, IMG_GLOBAL_OPTION_CSK);
        SetCenterSoftkeyFunction(mmi_clog_lt_lsk_hdlr, KEY_EVENT_UP);
    }
    redraw_center_softkey();
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_lsk_hdlr
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_lsk_hdlr(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_clog_lt_op_enter();
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_rsk_hdlr
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_rsk_hdlr(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_frm_scrn_close_active_id();
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_csk_hdlr
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_csk_hdlr(void)
{
#ifdef __MMI_WGUI_CSK_ENABLE__
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_clog_lt_viewer_enter();

#endif /* __MMI_WGUI_CSK_ENABLE__ */ 
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_ip_key_hdlr
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_ip_key_hdlr(void)
{
#ifdef __MMI_IP_KEY__
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif /* __MMI_IP_KEY__ */ 
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_send_key_hdlr
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_send_key_hdlr(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_clog_lt_act_proc(MMI_CLOG_OP_MID_MAKE_CALL, MMI_CLOG_ACT_FLAG_CALL_BY_SEND_KEY);
}

#ifdef __MMI_FTE_SUPPORT__


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_tb_create
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_tb_create(mmi_clog_lt_inst_struct *inst)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    U32 i;
    U32 j;
    U8 *enb_icons[MMI_CLOG_LT_TB_ID_MAX_ITEM];
    U8 *dis_icons[MMI_CLOG_LT_TB_ID_MAX_ITEM];
    U8 *strings[MMI_CLOG_LT_TB_ID_MAX_ITEM];
    const mmi_clog_lt_tb_struct *tb;
    const mmi_clog_lt_tb_item_struct *item;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!g_mmi_clog_lt_scrn_data.fte)
        return;
    tb = g_mmi_clog_lt_scrn_data.fte->tb;
    if (!tb || !tb->items || !tb->total_num)
        return;
    
    for (i = 0, j = 0; i < tb->total_num; i++)
    {
        item = &tb->items[i];
        if (!item)
            break;
        enb_icons[j] = (U8*) GetImage(item->enb_img_id);
        dis_icons[j] = (U8*) GetImage(item->dis_img_id);
        strings[j] = (U8*) get_string(item->str_id);
        j++;
    }
    wgui_icon_bar_setup(j++, enb_icons, dis_icons, strings, tb->tb_hdlr);

}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_tb_refresh
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_tb_refresh(mmi_clog_lt_inst_struct *inst)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U32 enb_bits;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    enb_bits = mmi_clog_lt_tb_get_enb_items(inst);
    mmi_clog_lt_tb_set_enb_state(inst, enb_bits, MMI_TRUE);
    wgui_icon_bar_update();
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_tb_get_enb_items
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static U32 mmi_clog_lt_tb_get_enb_items(mmi_clog_lt_inst_struct *inst)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 ret;
    U32 enb_bits = MMI_CLOG_LT_TB_ID_ALL;
    mmi_clog_lt_id_num_info_struct *num_info;
    srv_clog_log_struct log;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    num_info = mmi_clog_lt_get_num_info_by_lt_id(inst, inst->sel_lt_id);
    if (num_info->num_info.num[SRV_CLOG_LOG_NUM_TYPE_TOTAL_LOGS] == 0)
    {
        enb_bits = 0;
        return enb_bits;
    }
    ret = srv_clog_get_log_by_id(
            inst->log_data.handle,
            inst->sel_log_id[inst->sel_lt_id],
            SRV_CLOG_LOG_FIELD_IDENTITY | SRV_CLOG_LOG_FIELD_CID,
            &log);
    if (ret != SRV_CLOG_RET_OK || mmi_clog_is_cid_empty(&log))
    {
        enb_bits = 0;
        return enb_bits;
    }

    if (log.data.call_log.sub_type == SRV_CLOG_CALL_TYPE_VOIP)
    {
        MMI_CLOG_CLEAR_BIT(enb_bits, MMI_CLOG_LT_TB_ID_ALL_MSG);
    }
    else
    {
    #ifndef __MMI_UNIFIED_COMPOSER__
        if (srv_sms_is_hide_send_sms_menu_item())
            MMI_CLOG_CLEAR_BIT(enb_bits, MMI_CLOG_LT_TB_ID_SEND_SMS);

    #ifdef __MMI_MMS__
        if (!mms_is_ready())
            MMI_CLOG_CLEAR_BIT(enb_bits, MMI_CLOG_LT_TB_ID_SEND_MMS);
    #endif /* __MMI_MMS__ */ 
    #endif /* __MMI_UNIFIED_COMPOSER__ */ 
    }

    return enb_bits;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_tb_action_hdlr
 * DESCRIPTION
 *  
 * PARAMETERS
 *  index       [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_tb_action_hdlr(S32 index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    const mmi_clog_lt_tb_item_struct *item;
    mmi_clog_op_mid_enum op_mid = MMI_CLOG_LT_TB_ID_MAKE_CALL;
    mmi_clog_lt_inst_struct *inst;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    inst = (mmi_clog_lt_inst_struct*) mmi_clog_get_inst_by_act_gid();
    MMI_CLOG_ASSERT(MMI_CLOG_IS_INST_VALID(inst, MMI_CLOG_INST_TYPE_LT));

    item = mmi_clog_lt_get_tb_item_by_index(inst, index);
    switch (item->tb_id)
    {
        case MMI_CLOG_LT_TB_ID_MAKE_CALL:
            op_mid = MMI_CLOG_OP_MID_MAKE_CALL;
            break;

        case MMI_CLOG_LT_TB_ID_SEND_MSG:
            op_mid = MMI_CLOG_OP_MID_SEND_MSG;
            break;

        case MMI_CLOG_LT_TB_ID_SEND_SMS:
            op_mid = MMI_CLOG_OP_MID_SEND_SMS;
            break;

        case MMI_CLOG_LT_TB_ID_SEND_MMS:
            op_mid = MMI_CLOG_OP_MID_SEND_MMS;
            break;

        default:
            MMI_ASSERT(!"Wrong tb_idx");
            break;
    }

    mmi_clog_lt_act_proc(op_mid, 0);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_get_tb_item_by_index
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [?]         
 *  index       [IN]        
 * RETURNS
 *  
 *****************************************************************************/
static const mmi_clog_lt_tb_item_struct *mmi_clog_lt_get_tb_item_by_index(mmi_clog_lt_inst_struct *inst, S32 index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    const mmi_clog_lt_tb_struct *tb;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!g_mmi_clog_lt_scrn_data.fte)
        return NULL;

    tb = g_mmi_clog_lt_scrn_data.fte->tb;

    if (!tb || !tb->items || !tb->total_num)
        return NULL;

    MMI_ASSERT(index >= 0 && index < tb->total_num);

    return &tb->items[index];
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_set_tap_hdlr
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_set_tap_hdlr(mmi_clog_lt_inst_struct *inst)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    wgui_register_tap_callback(mmi_clog_lt_tap_action_hdlr);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_tb_set_enb_state
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [?]         
 *  ids         [IN]        
 *  enable      [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_tb_set_enb_state(mmi_clog_lt_inst_struct *inst, mmi_clog_lt_tb_id_enum ids, S32 enable)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U32 i;
    const mmi_clog_lt_tb_item_struct *item;
    const mmi_clog_lt_tb_struct *tb;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!g_mmi_clog_lt_scrn_data.fte)
        return;

    tb = g_mmi_clog_lt_scrn_data.fte->tb;

    if (!tb || !tb->items || !tb->total_num)
        return;
    
    for (i = 0; i < tb->total_num; i++)
    {
        item = &tb->items[i];
        if (!item)
            break;
        if (MMI_CLOG_CHECK_BIT(ids, item->tb_id))
        {
            wgui_icon_bar_set_item_enable_state(i, enable);
        }
        else
        {
            wgui_icon_bar_set_item_enable_state(i, !enable);
        }
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_tap_action_hdlr
 * DESCRIPTION
 *  
 * PARAMETERS
 *  tap_type        [IN]        
 *  index           [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_tap_action_hdlr(mmi_tap_type_enum tap_type, S32 index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (tap_type == ENUM_TAP_ON_HIGHLIGHTED_ITEM)
    {
        mmi_clog_lt_viewer_enter();
    }
}

#endif /* __MMI_FTE_SUPPORT__ */ 


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_op_enter
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_op_enter(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_clog_lt_inst_struct *inst;
    mmi_clog_op_para_struct para;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    inst = (mmi_clog_lt_inst_struct*) mmi_clog_get_inst_by_act_gid();
    MMI_CLOG_ASSERT(MMI_CLOG_IS_INST_VALID(inst, MMI_CLOG_INST_TYPE_LT));

    mmi_clog_op_init_para(&para);
    if (inst->lt_type == MMI_CLOG_LT_TYPE_LIST)
        para.type = MMI_CLOG_OP_TYPE_LT_LIST;
    else if (inst->lt_type == MMI_CLOG_LT_TYPE_TAB)
        para.type = MMI_CLOG_OP_TYPE_LT_TAB;
    else
    {
        MMI_CLOG_ASSERT(!"Wrong lt_type");
    }
    para.lt_id = inst->sel_lt_id;
    para.handle = inst->log_data.handle;
    para.log_id = inst->sel_log_id[inst->sel_lt_id];
    mmi_clog_op_enter(inst->self_gid, &para);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_viewer_enter
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_viewer_enter(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 ret;
    U32 merge_style;
    mmi_clog_lt_inst_struct *inst;
    mmi_clog_vr_create_struct create;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    inst = (mmi_clog_lt_inst_struct*) mmi_clog_get_inst_by_act_gid();
    MMI_CLOG_ASSERT(MMI_CLOG_IS_INST_VALID(inst, MMI_CLOG_INST_TYPE_LT));

    mmi_clog_vr_init_para(&create);
    create.handle = inst->log_data.handle;
    create.log_id = inst->sel_log_id[inst->sel_lt_id];

    create.mode = MMI_CLOG_VR_DEF_MODE;
    create.style = MMI_CLOG_VR_DEF_STYLE;
    if (inst->lt_type == MMI_CLOG_LT_TYPE_LIST)
        MMI_CLOG_SET_BIT(create.style, MMI_CLOG_VR_STYLE_LT_LIST);
    else if (inst->lt_type == MMI_CLOG_LT_TYPE_TAB)
        MMI_CLOG_SET_BIT(create.style, MMI_CLOG_VR_STYLE_LT_TAB);

    create.lt_type = inst->lt_type;
    create.sel_lt_id = inst->sel_lt_id;

    ret = srv_clog_get_def_style(SRV_CLOG_STYLE_TYPE_MERGE, &merge_style, NULL);
    if (ret == SRV_CLOG_RET_OK && merge_style)
        create.sup_merge = MMI_TRUE;

    inst->vr_gid = mmi_clog_vr_create(inst->self_gid, &create);
    mmi_clog_vr_run(inst->vr_gid);

}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_act_proc
 * DESCRIPTION
 *  
 * PARAMETERS
 *  op_mid      [IN]        
 *  flags       [IN]        
 * RETURNS
 *  
 *****************************************************************************/
static MMI_ID mmi_clog_lt_act_proc(mmi_clog_op_mid_enum op_mid, U32 flags)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_clog_lt_inst_struct *inst;
    mmi_clog_act_para_struct para;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    inst = (mmi_clog_lt_inst_struct*) mmi_clog_get_inst_by_act_gid();
    MMI_CLOG_ASSERT(MMI_CLOG_IS_INST_VALID(inst, MMI_CLOG_INST_TYPE_LT));

    mmi_clog_act_init_para(&para);
    para.handle = inst->log_data.handle;
    para.log_id = inst->sel_log_id[inst->sel_lt_id];
    para.op_mid = op_mid;
    para.sel_lt_id = inst->sel_lt_id;
    para.flags = flags;
    return mmi_clog_act_proc(inst->self_gid, &para);
}

#define MMI_CLOG_LT_LOG


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_log_start
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_log_start(mmi_clog_lt_inst_struct *inst)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U32 style;
    srv_clog_create_struct create;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!MMI_CLOG_CHECK_BIT(inst->flags, MMI_CLOG_CMN_INST_FLAG_EXT_HANDLE))
    {
        srv_clog_init_para(SRV_CLOG_PARA_CREATE, &create);
        create.user_data = inst;
        inst->log_data.handle = srv_clog_create(&create);
        MMI_ASSERT(inst->log_data.handle);
    }
    srv_clog_get_def_style(SRV_CLOG_STYLE_TYPE_MERGE, &style, NULL);
    if (style)
        MMI_CLOG_SET_BIT(inst->flags, MMI_CLOG_LT_FLAG_SUP_MERGE);
    if (MMI_CLOG_CHECK_BIT(style, SRV_CLOG_STYLE_MERGE_THREAD))
        MMI_CLOG_SET_BIT(inst->flags, MMI_CLOG_LT_FLAG_SUP_THREAD);

}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_refresh_data
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_refresh_data(mmi_clog_lt_inst_struct *inst)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_clog_lt_update_read_status(inst);
    mmi_clog_lt_load_num(inst);
    mmi_clog_lt_load_log_ids(inst);
    /* Can only refresh current index of select lt_id */
    mmi_clog_lt_refresh_sel_index(inst);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_update_read_status
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_update_read_status(mmi_clog_lt_inst_struct *inst)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U32 ur_num;
    const mmi_clog_lt_id_attr_struct *attr;
    srv_clog_update_all_logs_req_struct req_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!mmi_clog_is_valid_internal_gid(mmi_frm_group_get_active_id(), MMI_CLOG_GRP_TYPE_LT))
        return;

    if (inst->sel_lt_id != MMI_CLOG_LT_ID_MISSED_CALL && inst->sel_lt_id != MMI_CLOG_LT_ID_ALL_CALL)
        return;
    ur_num = srv_clog_get_unread_missed_call_num();
    if (ur_num == 0)
        return;

    MMI_TRACE(
        MMI_CLOG_TRC_INFO,
        TRC_MMI_CLOG_LT_UPDATE_READ_STATUS,
        inst->self_gid,
        inst->sel_lt_id,
        inst->sel_log_idx[inst->sel_lt_id],
        inst->sel_log_id[inst->sel_lt_id]);

    attr = mmi_clog_get_attr_by_lt_id(inst->sel_lt_id);
    srv_clog_init_para(SRV_CLOG_PARA_UPDATE_ALL_LOGS_REQ, &req_data);
    memcpy((srv_clog_log_identity_struct*) & req_data, &attr->idt, sizeof(srv_clog_log_identity_struct));
    req_data.req_fields = SRV_CLOG_LOG_FIELD_UNREAD_NUM;
    req_data.read = MMI_TRUE;
    srv_clog_update_all_logs(inst->log_data.handle, 0, &req_data, NULL);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_refresh_sel_index
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_refresh_sel_index(mmi_clog_lt_inst_struct *inst)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U32 i;
    U32 j;
    U32 max_num;
    U16 old_sel_idx;
    SRV_CLOG_ID old_sel_log_id;
    mmi_clog_lt_id_num_info_struct *num_info;
    SRV_CLOG_ID *id_list = inst->log_data.log_tbl.log_ids;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (SRV_CLOG_IS_ELM_INVALID(inst->sel_log_id[inst->sel_lt_id]))
    {
        mmi_clog_lt_update_sel_log_id(inst);
        return;
    }

    if (inst->sel_log_id[inst->sel_lt_id] == id_list[inst->sel_log_idx[inst->sel_lt_id]])
        return;

    old_sel_idx = inst->sel_log_idx[inst->sel_lt_id];
    old_sel_log_id = inst->sel_log_id[inst->sel_lt_id];
    num_info = mmi_clog_lt_get_num_info_by_lt_id(inst, inst->sel_lt_id);
    max_num = num_info->num_info.num[SRV_CLOG_LOG_NUM_TYPE_TOTAL_LOGS];
    for (i = 0, j = inst->sel_log_idx[inst->sel_lt_id]; i < max_num; i++)
    {
        if (j >= max_num)
            j = 0;
        if (old_sel_log_id == id_list[j])
        {
            inst->sel_log_idx[inst->sel_lt_id] = j;
            break;

        }
        j++;
    }

    if (i == max_num)   /* not found, must be deleted, try to highlight next one */
    {
        /* If some log before current selected one are deleted, should find the right index above,
           if current selected log or some log after this is deleted, just highlight next log,
           if current log is the last one, just highlight the previous one, 
           the rule is not to change user's view point except use make a call and merge it */
        if (inst->sel_log_idx[inst->sel_lt_id] > 0 && inst->sel_log_idx[inst->sel_lt_id] >= max_num)
        {
            inst->sel_log_idx[inst->sel_lt_id]--;
        }
        inst->sel_log_id[inst->sel_lt_id] = id_list[inst->sel_log_idx[inst->sel_lt_id]];
    }
    if (inst->sel_log_idx[inst->sel_lt_id] != old_sel_idx)
        MMI_CLOG_SET_BIT(inst->flags, MMI_CLOG_LT_FLAG_CUR_SEL_IDX_CHANGED);

    MMI_TRACE(
        MMI_CLOG_TRC_INFO,
        TRC_MMI_CLOG_LT_REFRESH_SEL_INDEX,
        old_sel_log_id,
        inst->sel_log_id[inst->sel_lt_id],
        old_sel_idx,
        inst->sel_log_idx[inst->sel_lt_id],
        MMI_CLOG_CHECK_BIT(inst->flags, MMI_CLOG_LT_FLAG_CUR_SEL_IDX_CHANGED));
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_load_num
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_load_num(mmi_clog_lt_inst_struct *inst)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U32 i;
    mmi_clog_lt_id_num_tbl_struct *num_tbl = &inst->log_data.num_tbl;
    const mmi_clog_lt_id_attr_struct *attr;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    for (i = 0; i < num_tbl->total_num; i++)
    {
        attr = mmi_clog_get_attr_by_lt_id(num_tbl->id_nums[i].lt_id);
        srv_clog_get_list_num_info(inst->log_data.handle, &attr->idt, &num_tbl->id_nums[i].num_info);
    }
    srv_clog_get_sim_unread_missed_call_num(num_tbl->ur_mclt_num, SRV_CLOG_SIM_IDX_MAX_ITEM);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_load_log_ids
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_load_log_ids(mmi_clog_lt_inst_struct *inst)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U32 i;
    U32 count;
    S32 ret;
    const mmi_clog_lt_id_attr_struct *attr;
    mmi_clog_lt_id_num_info_struct *id_num_info;
    srv_clog_get_list_log_ids_req_struct req_data;
    srv_clog_get_list_log_ids_cnf_struct *cnf_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    cnf_data = OslMalloc(sizeof(srv_clog_get_list_log_ids_cnf_struct));
    srv_clog_init_para(SRV_CLOG_PARA_GET_LIST_LOG_IDS_REQ, &req_data);
    srv_clog_init_para(SRV_CLOG_PARA_GET_LIST_LOG_IDS_CNF, cnf_data);

    attr = mmi_clog_get_attr_by_lt_id(inst->sel_lt_id);
    SRV_CLOG_INIT_IDT(
        (srv_clog_log_identity_struct*) & req_data,
        attr->idt.cate,
        attr->idt.sim_id,
        attr->idt.log_type,
        attr->idt.sub_type);
    req_data.start_by = SRV_CLOG_BY_ID;
    req_data.log_num = SRV_CLOG_LOG_ID_LIST_MAX_NUM;

    inst->log_data.log_tbl.total_num = 0;
    id_num_info = mmi_clog_lt_get_num_info_by_lt_id(inst, inst->sel_lt_id);
    count =
        (id_num_info->num_info.num[SRV_CLOG_LOG_NUM_TYPE_TOTAL_LOGS] + SRV_CLOG_LOG_ID_LIST_MAX_NUM -
         1) / SRV_CLOG_LOG_ID_LIST_MAX_NUM;
    for (i = 0; i < count; i++)
    {
        req_data.start_elm = cnf_data->next_start_elm;
        ret = srv_clog_get_list_log_ids(inst->log_data.handle, &req_data, cnf_data);
        if (ret != SRV_CLOG_RET_OK)
            break;
        memcpy(
            inst->log_data.log_tbl.log_ids + inst->log_data.log_tbl.total_num,
            cnf_data->log_ids,
            cnf_data->log_num * sizeof(SRV_CLOG_ID));
        inst->log_data.log_tbl.total_num += cnf_data->log_num;
        if (cnf_data->next_start_elm == SRV_CLOG_INVALID_ELM)
            break;
    }
    memset(
        inst->log_data.log_tbl.log_ids + inst->log_data.log_tbl.total_num,
        0x0,
        (SRV_CLOG_LOG_MAX_NUM - inst->log_data.log_tbl.total_num) * sizeof(SRV_CLOG_ID));
    OslMfree(cnf_data);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_srv_evt_hdlr
 * DESCRIPTION
 *  
 * PARAMETERS
 *  evt     [IN]     
 * RETURNS
 *  
 *****************************************************************************/
MMI_RET mmi_clog_lt_srv_evt_hdlr(mmi_event_struct *evt)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U32 i;
    mmi_clog_lt_inst_struct *inst;
    mmi_clog_lt_cntx_struct *cntx = mmi_clog_lt_get_cntx();

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    for (i = 0; i < MMI_CLOG_LT_INST_MAX_NUM; i++)
    {
        inst = &cntx->inst_list[i];
        if (!MMI_CLOG_IS_INST_VALID(inst, MMI_CLOG_INST_TYPE_LT))
            continue;

        if (inst->log_data.handle == ((srv_clog_evt_log_op_struct*) evt)->handle)
            continue;

        mmi_clog_lt_inst_srv_evt_hdlr(inst, evt);
    }
    return MMI_RET_OK;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_inst_srv_evt_hdlr
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]     
 *  evt         [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_inst_srv_evt_hdlr(mmi_clog_lt_inst_struct *inst, mmi_event_struct *evt)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    switch (evt->evt_id)
    {
        case EVT_ID_SRV_CLOG_ADD_LOG:
            mmi_clog_lt_inst_srv_evt_add_log_hdlr(inst, evt);
            break;

        case EVT_ID_SRV_CLOG_DEL_LOG:
        case EVT_ID_SRV_CLOG_DEL_ALL:
        case EVT_ID_SRV_CLOG_UPDATE_LOG:
        case EVT_ID_SRV_CLOG_UPDATE_ALL:
            mmi_clog_lt_refresh_int(inst);
            break;

        default:
            break;
    }

}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_inst_srv_evt_add_log_hdlr
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]     
 *  evt         [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_inst_srv_evt_add_log_hdlr(mmi_clog_lt_inst_struct *inst, mmi_event_struct *evt)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_clog_evt_add_log_struct *srv_evt = (srv_clog_evt_add_log_struct*) evt;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (srv_evt->add_ret == SRV_CLOG_ADD_LOG_RET_PURE_MERGE)
    {
        MMI_CLOG_ASSERT(!SRV_CLOG_IS_ELM_INVALID(srv_evt->old_idf.log_id));
        if (inst->sel_log_id[inst->sel_lt_id] == srv_evt->old_idf.log_id)
        {
            /* Set new log id here, and will update the sel_idx in mmi_clog_lt_refresh_int after reload the data */
            inst->sel_log_id[inst->sel_lt_id] = srv_evt->new_idf.log_id;

            MMI_TRACE(
                MMI_CLOG_TRC_INFO,
                TRC_MMI_CLOG_LT_INST_SRV_EVT_ADD_LOG_HDLR,
                srv_evt->add_ret,
                inst->sel_lt_id,
                inst->sel_log_idx[inst->sel_lt_id],
                inst->sel_log_id[inst->sel_lt_id],
                srv_evt->new_idf.log_id);

        }
    }
    mmi_clog_lt_refresh_int(inst);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_clog_lt_srv_evt_refresh_hdlr
 * DESCRIPTION
 *  
 * PARAMETERS
 *  inst        [IN]     
 *  evt         [IN]     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_clog_lt_srv_evt_refresh_hdlr(mmi_clog_lt_inst_struct *inst, srv_clog_evt_refresh_struct *evt)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
}

